package com.yonyou.pmclouds.alter.rmiimpl;

import com.yonyou.pmclouds.alter.entity.AlterVO;
import com.yonyou.pmclouds.alter.rmiitf.AlterQuery;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.ref.itf.RefCodeConst;
import com.yonyou.pmclouds.basecom.ref.itf.ReferenceCheckOfBusiness;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ReferenceCheckOfAlter implements ReferenceCheckOfBusiness {
    @Autowired
    private AlterQuery query;
    @Override
    public String[] getReferenceCode() {

        return new String[]{RefCodeConst.PROJECT, RefCodeConst.ALTERCATEGORY};
    }

    @Override
    public boolean checkReferenced(String bdCode, String[] keys) throws BusinessException {
        String code = null;
        if(RefCodeConst.PROJECT.equals(bdCode)) {
            code = AlterVO.PK_PROJECT;
        } else if(RefCodeConst.ALTERCATEGORY.equals(bdCode)){
            code = AlterVO.PK_CATEGORY;
        } else {
            throw new BusinessException("变更申请暂未引用该档案!");
        }
        return query.queryRefByIds(code, keys);
    }
}
